<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-date"></i>{{$route.name}}
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div>
          <el-table :data="tableData" border fit style="width: 100%">
              <el-table-column prop="content" label="内容" show-overflow-tooltip>
              </el-table-column>
              <el-table-column prop="decisionId" label="决策调研" show-overflow-tooltip 
              >
              </el-table-column>
              <el-table-column fixed="right" label="操作">
                  <template slot-scope="scope">
                  </template>
              </el-table-column>
          </el-table>
        </div>
        <div class="block">
            <el-pagination @current-change="handleCurrentChange" :current-page="page.number" 
            layout="total, prev, pager, next, jumper" :total="page.total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import { decision, downlaodFile } from '../../server/getDate.js'
import { mapState, mapActions } from 'vuex'
const { questionListApi } = decision
  export default {
    data() {
      return {
        searchKey: '',
        multipleSelection: []
      }
    },
    computed: mapState({
      tableData: state => state.Decision.questionList,
      page: state => state.Decision.questionPage
    }),
    created() {
      this.getList(1)
    },
    methods: {
      ...mapActions(['saveQuestion']),
      getList(number) {
        const params = {
          page: number,
          pageSize: 10
        }
        if (this.searchKey !== '') {
          params.searchKey = this.searchKey
        }
        questionListApi({ ...params }).then(res => {
          if (res.code === '000000') {
            this.saveQuestion({
              ...res,
              number
            })
          } else {
            this.$message.error(res.message)
          }
        }, () => {
          this.$message.error('网络错误')
        })
      },
      toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      search() {
        this.getList(this.page.number)
      },
      handleCurrentChange(val) {
          this.getList(val)
      },
      onDownload() {
        if (this.multipleSelection.length === 0) {
          this.$message.info('请选择下载问卷')
          return
        } else {
          //download
        }
      }
    }
  }
</script>

<style lang='less' scoped>
.handle-box {
  margin-bottom: 1%;
  .search {
    width: 30%;
  }
}
.block {
  text-align: center;
  margin-top: 1%;
}
</style>
